package cn.com.eado.crm.m.db

import android.os.Parcel
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "app_icon")
data class AppIcon(
    @PrimaryKey(autoGenerate = true)
    var id: Int,
    var userId: Int,

    val name: String?,
    val resId: Int,
    var show: Boolean,
    var delete: Boolean
) : Parcelable {
    constructor(source: Parcel) : this(
        source.readInt(),
        source.readInt(),
        source.readString(),
        source.readInt(),
        1 == source.readInt(),
        1 == source.readInt()
    )

    override fun describeContents() = 0

    override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
        writeInt(id)
        writeInt(userId)
        writeString(name)
        writeInt(resId)
        writeInt((if (show) 1 else 0))
        writeInt((if (delete) 1 else 0))
    }

    companion object {
        @JvmField
        val CREATOR: Parcelable.Creator<AppIcon> = object : Parcelable.Creator<AppIcon> {
            override fun createFromParcel(source: Parcel): AppIcon = AppIcon(source)
            override fun newArray(size: Int): Array<AppIcon?> = arrayOfNulls(size)
        }
    }
}